﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;
using SXT.Party.Utility;

namespace ZHDJ.MobileInterface
{
    public partial class GetLawyerList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            LawyerListOutParam result = new LawyerListOutParam();
            LawyerListInParam param = new LawyerListInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as LawyerListInParam;


                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                }

                if (isFlag)
                {
                    DataSet ds = SXT.Party.Law.Model.PartyLawyer.GetGirdData(param.LawyerName, param.page_no, param.page_count, "MobileService");
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        LawyerData itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new LawyerData();
                            itemTemp.LawyerID = dr["LoginID"].ToString();
                            itemTemp.LawyerName = dr["UserName"].ToString();
                            itemTemp.ConsultationCount = dr["ConsultationCount"].ToString();
                            itemTemp.ScoreLove = dr["ScoreLove"].ToString();
                            itemTemp.DianZan = dr["DianZan"].ToString();
                            itemTemp.RegistrationNum = dr["RegistrationNum"].ToString();
                            itemTemp.LawFirmName = dr["LawFirmName"].ToString();
                            itemTemp.Talents = dr["Talents"].ToString();

                            var day = (DateTime.Now - Convert.ToDateTime(dr["JobTime"])).Days;
                            itemTemp.JobTime = Convert.ToString(day / 356 + (day % 356 > 200 ? 1 : 0));

                            var PID = PageUtility.GetImageUrl(Convert.ToString(dr["PicturID"]), "_small");
                            if(string.IsNullOrEmpty(PID))
                            {
                                itemTemp.PicturID = "http://www.ith71.cn/Resource/themes/default/images/Party/Party-Emblem.jpg";
                            }
                            else
                            {
                                itemTemp.PicturID = PID.Replace("/fs/UploadFiles/Party","http://www.ith71.cn/fs/UploadFiles/Party");
                                itemTemp.PicturID = PID.Replace("/fs/UploadFiles/party", "http://www.ith71.cn/fs/UploadFiles/Party");
                            }

                            result.data.list.Add(itemTemp);
                        }

                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetLawyerList", SerializeHelper.JsonSerializer<LawyerListInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<LawyerListInParam, LawyerListOutParam>();
            else
                SafeProcessRequest<LawyerListInParam, LawyerListOutParam>();
        }
    }

    #region 请求参数
    public class LawyerListInParam
    {
        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }

        /// <summary>
        /// 律师名称
        /// </summary>
        public string LawyerName
        { get; set; }

    }
    #endregion


    #region 结果参数
    public class LawyerListOutParam
    {
        public LawyerListOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LawyerList();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        public LawyerList data
        { get; set; }

    }

    public class LawyerList
    {
        public LawyerList()
        {
            total_pages = 0;
            list = new List<LawyerData>();
        }

        public List<LawyerData> list { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    public class LawyerData
    {
        /// <summary>
        /// ID
        /// </summary>
        public string LawyerID
        { get; set; }

        /// <summary>
        /// 律师名称
        /// </summary>
        public string LawyerName
        { get; set; }

        /// <summary>
        /// 咨询次数
        /// </summary>
        public string ConsultationCount
        { get; set; }

        /// <summary>
        /// 爱心积分
        /// </summary>
        public string ScoreLove
        { get; set; }

        /// <summary>
        /// 点赞数
        /// </summary>
        public string DianZan
        { get; set; }
        
        /// <summary>
        /// 执业时间
        /// </summary>
        public string JobTime
        { get; set; }

        /// <summary>
        /// 执业证号
        /// </summary>
        public string RegistrationNum
        { get; set; }

        /// <summary>
        /// 事务所
        /// </summary>
        public string LawFirmName
        { get; set; }

        public string PicturID
        { get; set; }

        /// <summary>
        /// 擅长
        /// </summary>
        public string Talents
        { get; set; }
    }
    #endregion
}